#include <iostream>

#include <meeting/meeting.pp.h>

int main(int argc, char* argv[])
{
    meeting::MeetingData md;
    pp::ByteArray buf(128);
    //md.ObtainMeetingList()->Add
    std::shared_ptr<meeting::MeetingInfo> mi = std::make_shared<meeting::MeetingInfo>();
    md.ObtainMeetingList()->AddMeetingInfos(mi);
    mi->AddChatters(17);
    mi->AddChatters(89);
    mi->AddListeners("xxyy");
    mi->AddListeners("jidess");
    mi->AddListeners("🇨🇳对其jiiu====☀️");
    mi->SetReduceRate(12456.789);
    mi->SetPrice(-90.789);
    mi->SetMeetingState(meeting::MEETING_STATE_CANCEL);
    mi->SetMeetingType(meeting::MEETING_TYPE_AUDIO);
    std::shared_ptr<meeting::MeetingInfo> mi2  = md.ObtainMeetingList()->AddMeetingInfos();
    mi2->AddChatters(27);
    mi2->AddChatters(99);
    mi2->AddListeners("ppooiii");
    mi2->AddListeners("yxbbdg");
    mi2->AddListeners("中国在这里等了你!");
    mi2->SetReduceRate(-42.758);
    mi2->SetPrice(-93764.8903);
    mi2->SetMeetingState(meeting::MEETING_STATE_END);
    mi2->SetMeetingType(meeting::MEETING_TYPE_VIDEO);

    std::shared_ptr<common::KeyValue> kv1 = std::make_shared<common::KeyValue>();
    kv1->SetKey("test");
    kv1->SetValue("value");
    md.ObtainMeetingList()->AddMemberInfos(kv1);
    md.ObtainMeetingList()->ObtainUserKey()->SetKey("ttt!");
    md.ObtainMeetingList()->ObtainUserKey()->SetValue("ppp!");

    md.Encode(buf, 0xFFFFFFFFFFFFFFFF);

    std::cout << buf.ToPrintable() << std::endl;

    meeting::MeetingData md2;
    std::cout << "iRet:" << md2.Decode(buf.Data(), buf.Length()) << std::endl;

    std::cout << md2.ToJson() << std::endl;
    std::cout << md2.ToString() << std::endl;
    uint64_t u64Tag;
    std::cout << pp::Message::DecodeTag(buf.Data(), buf.Length(), u64Tag) << std::endl;
    std::cout << u64Tag << std::endl;

    // bad one:(解码不发生错误或崩溃)
    char test[] = {
        0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0xEE, 0x01, 0x00, 0xEB, 0x01, 0x01,
        0x65, 0x01, 0x03, 0x78, 0x79, 0x7A, 0x02, 0x01, 0x01, 0x03, 0x01, 0x03, 0x04, 0x08, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x05, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11,
        0x05, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x59, 0x06, 0x04, 0x78, 0x78, 0x79, 0x79,
        0x06, 0x06, 0x6A, 0x69, 0x64, 0x65, 0x73, 0x73, 0x06, 0x10, 0xF0, 0x9F, 0x87, 0xA8, 0xF0, 0x9F,
        0x87, 0xB3, 0xE5, 0xAF, 0xB9, 0xE5, 0x85, 0xB6, 0x6A, 0x69, 0x69, 0x75, 0x3D, 0x3D, 0x3D, 0x3D,
        0xE2, 0x98, 0x80, 0xEF, 0xB8, 0x8F, 0x07, 0x08, 0x40, 0xC8, 0x54, 0x64, 0xFD, 0xF3, 0xB6, 0x46,
        0x08, 0x04, 0xC2, 0xB5, 0x93, 0xF8, 0x01, 0x65, 0x01, 0x03, 0x78, 0x79, 0x7A, 0x02, 0x01, 0x02,
        0x03, 0x01, 0x02, 0x04, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x05, 0x08, 0x00,
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1B, 0x05, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x63, 0x06, 0x07, 0x70, 0x70, 0x6F, 0x6F, 0x69, 0x69, 0x69, 0x06, 0x06, 0x79, 0x78, 0x62, 0x62,
        0x64, 0x67, 0x06, 0x09, 0xE4, 0xB8, 0xAD, 0xE5, 0x9B, 0xBD, 0xE5, 0x9C, 0xA8, 0xE8, 0xBF, 0x99,
        0xE9, 0x87, 0x8C, 0xE7, 0xAD, 0x89, 0xE4, 0xBA, 0x86, 0xE4, 0xBD, 0xA0, 0x21, 0x07, 0x08, 0xC0,
        0x45, 0x61, 0x06, 0x24, 0xDD, 0x2F, 0x1B, 0x08, 0x04, 0xC7, 0xB7, 0x22, 0x72, 0x02, 0x0C, 0x01,
        0x04, 0x74, 0x74, 0x74, 0x21, 0x02, 0x04, 0x70, 0x70, 0x70, 0x21, 0x03, 0x0D, 0x01, 0x04, 0x74,
        0x65, 0x73, 0x74, 0x02, 0x05, 0x76, 0x61, 0x6C, 0x75, 0x65
    };

    meeting::MeetingData md3;
    std::cout << "长度：" << sizeof(test) << std::endl;
    int iRet = md3.Decode(test, sizeof(test));
    std::cout << "iRetw:" << iRet << std::endl;
    printf("iReta:%d\n", iRet);

    std::cout << md3.ToJson() << std::endl;
    std::cout << md3.ToString() << std::endl;

    return 0;
}
